#include"openview.h"
OpenView::OpenView()
{
    this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

    this->initView();
    this->resize(600,900);
}

void OpenView::initView()
{
    this->title=new QLabel("执法记录仪 执法一号",this);

    QFont font = this->title->font();  // 获取当前字体
      font.setPointSize(20);  // 设置字体大小为 20
      font.setFamily("Arial");
      font.setBold(true);
         // 设置字体倾斜
         font.setItalic(true);
      this->title->setFont(font);  // 应用新字体

      // 设置文本居中显示
      //this->title->setAlignment(Qt::AlignCenter);

    this->title->move(100,100);
    this->Scene=new QGraphicsScene();
    this->setScene(this->Scene);
    //设置舞台的坐标
    this->setSceneRect(0,0,this->width(),this->height());

    qDebug() << "View width: " << this->width() << ", height: " << this->height();


    //隐藏滚动条
    this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);



    //演员就位
    this->police=new OpenItem("../image/police.png",true);
    this->Scene->addItem(this->police);

    this->police->setPos(500,100);

    this->thief=new OpenItem("../image/thief.png",false);
    this->Scene->addItem(this->thief);
    this->thief->setPos(100,100);


    this->timer=new QTimer();
    //启动计时器
    this->timer->start(60);
    //计时槽函数
    connect(this->timer,&QTimer::timeout,this,&OpenView::autoMove);


}

void OpenView::autoMove()
{
    if(this->police->collidesWithItem(this->thief))
    {
        this->timer->stop();
//        disconnect(timer, &QTimer::timeout, this, &OpenView::autoMove);
        emit isHide();
    }
        this->Scene->advance();
}


